package leo.mystudy.executors;

import java.util.concurrent.*;

/**
 * @author lichao email:lichao@witspring.com
 * @Description: 定时线程池
 * @Date 2018/4/23 18:54
 * @since Ver V0.0.1
 */
public class ScheduledThreadPool {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ScheduledExecutorService exec = Executors.newScheduledThreadPool(3);
        Executors.newWorkStealingPool();
        ScheduledFuture future = exec.scheduleAtFixedRate(() -> {
            System.out.println("启动子线程：" + Thread.currentThread().getName());
            try {
                Thread.sleep(2000L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(System.currentTimeMillis());
        }, 1, 2, TimeUnit.SECONDS);
        future.get();
        while (true) {
            if (exec.isTerminated()) {
                System.out.println("主程序完成");
                break;
            }
        }
    }
}
